Addons.Pagecontrol = new Class({
    VARS: {},
    REQUIRE: [],
    IMPLEMENT: [],
    ARELOCALHOST: ['localhost', '127.0.0.1'],
    ISLOCALHOST: false,
    ISFRAME: false,

    construct: function () {
        var parent = this;

        this.VARS = Sarue.Tools.getVars(window.location.href || '');

        var loadeds = [], imploaders = [];

        this.ISFRAME = (window && window.parent && window.parent !== window);

        this._scopes(function (scope) {

            if (scope.ARELOCALHOST && scope.ARELOCALHOST.indexOf(window.location.host))
                parent.ISLOCALHOST = true;

            if (scope.REQUIRE) {
                for (var c = 0; c < scope.REQUIRE.length; c++) {
                    var load = scope.REQUIRE[c];

                    if (loadeds.indexOf(load) == -1) {
                        loadeds.push(load);
                        Class.require(load);
                    }
                }
            }
			
			if (scope.IMPLEMENT) {
                for (var d = 0; d < scope.IMPLEMENT.length; d++) {
                    var implement = scope.IMPLEMENT[d];
					
                    if (imploaders.indexOf(implement) == -1) {
						var match = implement.match(/Addons.([^\.]+)$/);
							match = match ? match[0] + '.' + match[1] : implement;
							
						    imploaders.push(implement);
						
						function fnImplement(){
							var nclass = Class.exists(implement);
							
							if (nclass) {
								scope._implement(nclass);
								
								if(nclass.prototype.propertys.construct)
									nclass.prototype.propertys.construct.apply(parent);
							}
						};
									
                        Class.require(match, fnImplement, fnImplement, false, true);
                    }
                }
            }
        });

        Sarue.Require.options.complete = function () {
            if (parent.loader)
                parent.loader.apply(this, arguments);
        };

        Sarue.Require.options.finish = function (x) {
            if (parent.ready)
                parent.ready.apply(this, arguments);
        }

        if (this.pagecontrol)
            this.pagecontrol();
    },

    //loader is a method that is called whenever a script is loaded, successfully or unsuccessfully
    loader: function (obj, success) { },

    //ready method is called when all scripts have been loaded successfully, from here you are sure that the addons are ready for use
    ready: function () { }
});
